package duppentity.dto;

import java.io.Serializable;
import java.util.*;

/**
 * Dupp返回的结果集合，支持列表循环
 * @author zhangzc@djcars.cn
 * @create 2017/1/19
 */
public class ResultList<T> implements Serializable {

    /**
     * Dupp错误码
     */
    public Integer errorCode;

    /**
     * Dupp结果是否错误, 当error=true, errorMsg存放错误信息
     */
    public Boolean error;

    /**
     * Dupp错误信息
     */
    public String errorMsg;

    /**
     * 列表总条目
     */
    public Integer total = 0;

    public Integer offset = 0;

    public Object  params=0;

    public long lastId = 0;

    /**
     * 列表
     */
    public List<T> list;

    public ResultList() {
        list = new ArrayList<T>();
    }

    public ResultList(int initSize){
        list = new ArrayList(initSize);
    }

    //@Override
    public int size() {
        return list.size();
    }

    //@Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    //@Override
    public boolean contains(Object o) {
        return list.contains(o);
    }

    //@Override
    public Iterator iterator() {
        return list.iterator();
    }

    //@Override
    public Object[] toArray() {
        return list.toArray();
    }

    //@Override
    public boolean add(Object o) {
        return list.add((T) o);
    }

    //@Override
    public boolean remove(Object o) {
        return list.remove(o);
    }

    //@Override
    public boolean addAll(Collection c) {
        boolean r = true;
        for(Object o : c){
            r = add(o);
            if(!r){
                return r;
            }
        }
        return r;
    }

    //@Override
    public boolean addAll(int index, Collection c) {
        return list.addAll(index, c);
    }

    //@Override
    public void clear() {
        list.clear();
    }

    //@Override
    public T get(int index) {
        return list.get(index);
    }

    //@Override
    public T set(int index, Object element) {
        return list.set(index, (T) element);
    }

    //@Override
    public void add(int index, Object element) {
        list.add(index, (T) element);
    }

    //@Override
    public T remove(int index) {
        return list.remove(index);
    }

    //@Override
    public int indexOf(Object o) {
        return list.indexOf(o);
    }

    //@Override
    public int lastIndexOf(Object o) {
        return list.lastIndexOf(o);
    }

    //@Override
    public ListIterator<T> listIterator() {
        return list.listIterator();
    }

    //@Override
    public ListIterator<T> listIterator(int index) {
        return list.listIterator(index);
    }

    //@Override
    public List<T> subList(int fromIndex, int toIndex) {
        return list.subList(fromIndex, toIndex);
    }

    //@Override
    public boolean retainAll(Collection c) {
        return list.retainAll(c);
    }

    //@Override
    public boolean removeAll(Collection c) {
        return list.removeAll(c);
    }

    //@Override
    public boolean containsAll(Collection c) {
        return list.containsAll(c);
    }

    //@Override
    public Object[] toArray(Object[] a) {
        return list.toArray(a);
    }
}
